﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.EliminationOrDath.API.Application.Command.SheepDeathCommand;
using S.EliminationOrDath.API.Dtos;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
using Authorization.Center.Controllers;
using Authorization.Center.SqlServer;
using Microsoft.AspNetCore.Authorization;

namespace S.EliminationOrDath.API.Controllers
{
    /// <summary>
    /// 羊只死亡——写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SheepDeathController : BaseController
    {
        private readonly IMediator _mediator;
        public SheepDeathController(IMediator mediator,MySqlDbContext _db):base(_db)
        {
            _mediator= mediator;
        }
        /// <summary>
        /// 取消审核方法
        /// </summary>
        /// <param name="DeathIds"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> UpdAuditorTwo(string? DeathIds)
        {
            SheepUpdAuditorTwoCommand command=new SheepUpdAuditorTwoCommand();
            command.DeathIds= DeathIds;
            var result = await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 批量审核审核方法
        /// </summary>
        /// <param name="DeathIds"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> UpdAuditor(string? DeathIds,string? uname)
        {
            SheepUpdAuditorCommand command = new SheepUpdAuditorCommand();
            command.DeathIds = DeathIds;
            command.uname = uname;
            var result = await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 根据ids进行羊只死亡批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> BatchReomve(List<int> ids)
        {
            SheepDeathBatchRemoveCommand command = new SheepDeathBatchRemoveCommand();
            command.ids = ids;
            var result = await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 批量添加羊只死亡信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> BatchAddDeath(List<DeathDto> model)
        {
            //foreach (var item in model)
            //{
            //    item.CreateBy = UserStrategyDto.UserTrueName;
            //}
            return Ok(await _mediator.Send(new SheepDeathBatchAddCommand() { BatchDeath = model }));
        }

        /// <summary>
        /// 修改羊只死亡信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> UpdSheepDeatch(SheepDeathUpdateCommand command)
        {
            command.UpdateBy = "王五";
            command.UpdateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            command.CreateBy = "张三";
            command.CreateDate = DateTime.Now;
            var result=await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 根据羊只死亡主键Id进行单删
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> RemoveSheepDeatch(int id)
        {
            SheepDeathRemoveCommand command=new SheepDeathRemoveCommand();
            command.DeathId=id;
            var result=await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 添加羊只死亡信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddSheepDeatch(SheepDeathCreateCommand command)
        {
            command.CreateBy = "张三";
            command.CreateDate= DateTime.Now;
            command.UpdateBy = "";
            command.UpdateDate = "";
            var result=await _mediator.Send(command);
            return Ok(result);
        }
    }
}
